module.exports = {
	prefix: "/bus/extend/MA",
	get: {
		"/detail/by_id/:MA_id": function() {
			var MA_id = this.params.MA_id;
			var query = this.request.query;
			var bus = role.getBus(this);

			this.body = ResponObj("json", bus.getMADetail(MA_id))
		},
		"/list": function() {
			var bus = role.getBus(this);
			this.body = ResponObj("json", bus.getMAList());
		},
		"/get_config": function() {
			var bus = role.getBus(this);
			this.body = ResponObj("json", bus.getMAConfig());
		},
		"/get_ma_list_with_ach_detail_list_by_filter": function() {
			var bus = role.getBus(this);
			this.body = ResponObj("json", bus.getMAListWithAchDetailListByFilter(this.request.query));
		}
	},
	post: {
		"/add_MA": function() {
			var bus = role.getBus(this);
			var body = this.request.body;
			var MA = bus.addMA(body);

			if (body.return_type === "MA_list") {
				this.body = ResponObj("json", bus.getMADetailList());
			} else {
				this.body = ResponObj("json", bus.getMADetail(MA._id));
			}
		}
	},
	put: {
		"/update_MA/:MA_id": function() {
			var bus = role.getBus(this);
			var MA_id = this.params.MA_id;
			var body = this.request.body;
			bus.updateMA(MA_id, body);

			if (body.return_type === "MA_list") {
				this.body = ResponObj("json", bus.getMADetailList());
			} else {
				this.body = ResponObj("json", bus.getMADetail(MA_id));
			}
		},
		"/set_config": function() {
			var bus = role.getBus(this);
			this.body = ResponObj("json", bus.setMAConfig(this.request.body));
		}
	},
	"delete": {
		"/remove_MA/:MA_id": function() {
			var bus = role.getBus(this);
			var MA_id = this.params.MA_id;
			var body = this.request.body;
			bus.removeMA(MA_id);
			this.body = ResponObj("json", bus.getMADetailList());
		}
	}
}
var role = require("./role");
var BusCon = require("../../core/bus/_con");
var UserCon = require("../../core/user/_con");
var GoodsCon = require("../../core/goods/_con");
var AchCon = require("../../core/ach/_con");
var db = require("../../core/db/index");
var config = require("../../core/_include/config");
var ResponObj = require("../_include/responObj");